package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.PermissionDao;
import com.itheima.dao.RoleDao;
import com.itheima.dao.UserDao;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

/*
类简介：

功能：

时间：2020/4/9

*/
@Service(interfaceClass = UserService.class)
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Autowired
    PermissionDao permissionDao;

    @Autowired
    RoleDao roleDao;


    @Override
    public User findByUsername(String username) {
        User user = userDao.findByUsername(username);
        if (user == null){
            return null;
        }

        user.setRoles(roleDao.findRolesById(user.getId()));
        if (user.getRoles() != null){
            for (Role role : user.getRoles()) {
                role.setPermissions(permissionDao.findPermissionsById(role.getId()));
            }
        }
        return user;
    }
}
